package com.yitiao.service;

import com.yitiao.domain.CommerceOrder;
import com.yitiao.mapper.CommerceOrderMapper;
import com.yitiao.sender.TransMessageSender;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import java.util.Date;

@Service
@RequiredArgsConstructor
@Slf4j
public class CommerceOrderService {
    private final CommerceOrderMapper orderMapper;

    private final TransMessageSender messageSender;

    public void addOrder(CommerceOrder order){
        order.setCreateTime(new Date());
        orderMapper.insert(order);
        messageSender.send(
                "exchange.order",
                "key.restaurant",
                order
        );
        log.info("order message send");
    }
}
